/*
 * @lc app=leetcode.cn id=965 lang=javascript
 *
 * [965] 单值二叉树
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} root
 * @return {boolean}
 */
var isUnivalTree = function(root) {
   let single=root.val
   let dfs=function(node){
       if(!node)return true
       if(node.val!==single)return false
       return dfs(node.left)&&dfs(node.right)
   }
   return dfs(root)
};
// @lc code=end

var isUnivalTree = function(root) {
    let single=root.val
    let queue=[root]
    while(queue.length){
        let node=queue.pop()
        if(node.val!==single)return false
        if(node.left)queue.push(node.left)
        if(node.right)queue.push(node.right)
    }
    return true
};//bfs